package DieSiedler;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * Eine Hilfsklasse um komplexe Datenstruren zu kopieren.
 * @author Sebastian Kummer
 *
 */
public class DeepCopy {

	public static Object serialClone(Object o) throws IOException, ClassNotFoundException{
		//Serialisieren des Objekts
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		ObjectOutputStream os = new ObjectOutputStream(out);
		os.writeObject(o);
		os.flush();
		
		//Deserialisieren des Objekts
		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
		ObjectInputStream is = new ObjectInputStream(in);
		Object ret = is.readObject();
		is.close();
		os.close();
		
		return ret;
	}
	
}